package com.ewzj.bigdata.mvp.ui.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewzj.bigdata.R;
import com.ewzj.bigdata.mvp.model.bean.HouseTypeBean;

import java.util.List;

/**
 * author:zhangjing
 * 作用:
 * return:
 */

public class TypeAdapter extends BaseQuickAdapter<HouseTypeBean,BaseViewHolder> {
    private TypechageListener listener;
    public TypeAdapter(List<HouseTypeBean> data) {
        super(R.layout.item_hotkey, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, final HouseTypeBean houseTypeBean) {
        baseViewHolder.setText(R.id.tv_tag,houseTypeBean.getName());
        TextView textView=baseViewHolder.getView(R.id.tv_tag);
        textView.setSelected(houseTypeBean.isslected());
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                houseTypeBean.setIsslected(true);
                for (int i=0;i<mData.size();i++){
                    if (mData.get(i)!=houseTypeBean){
                        mData.get(i).setIsslected(false);
                    }
                }
                notifyDataSetChanged();
                if (listener!=null){
                    listener.typeChange(houseTypeBean.getName());
                }
            }
        });
    }

    public TypechageListener getListener() {
        return listener;
    }

    public void setListener(TypechageListener listener) {
        this.listener = listener;
    }

    public interface TypechageListener{
        void typeChange(String name);
    }
}
